let exec = require("../DBhelper").exec
class Register {
    async register(req, res) {
        let { phone, username, password } = req.body
        let sql = "select * from users where status=1 and phone=?"
        let params = [phone]
        let result = await exec(sql, params)
        let isRegister = result && result.length >= 1
        if(!isRegister){
            let sql_insert="insert into users (username,phone,password) value(?,?,?)";
            let insertResult=await exec(sql_insert,[username,phone,password])
            let isInsert=insertResult.affectedRows>=1
            res.json({msg:isInsert? "注册成功":"注册失败",code:isInsert? 1:-1})
        }else{
            res.json({msg:"此手机号已经注册",code:-1})
        }
        

    }
}


module.exports = new Register()